from typing import List


class Solution:
    def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
        if len(matrix) == 0:
            return []
        x, y = 0, 0
        res = []
        a, b = len(matrix) - 1, len(matrix[0]) - 1
        while x < len(matrix) / 2 and y < len(matrix[0])/2:
            n, m = x, y
            if x == a:
                while y <= b:
                    res.append(matrix[x][y])
                    y += 1
                break
            if y == b:
                while x <= a:
                    res.append(matrix[x][y])
                    x += 1
                break
            while y < b:
                res.append(matrix[x][y])
                y += 1
            while x < a:
                res.append(matrix[x][y])
                x += 1
            while y > m:
                res.append(matrix[x][y])
                y -= 1
            while x > n:
                res.append(matrix[x][y])
                x -= 1
            a, b, x, y = a - 1, b - 1, x + 1, y + 1
        return res

t = Solution().spiralOrder([
    [1,11],
    [2,12],
    [3,13],
    [4,14],
    [5,15],
    [6,16],
    [7,17],
    [8,18],
    [9,19],
    [10,20]])
print(t)